/*author:2012190218,WangChenghua*/
/*gitee:https://gitee.com/wangchsoft/hdoj*/
function swap(Array,i,j){
    const temp=Array[i];
    Array[i] = Array [j];
    Array[j] = temp;
}

function Part_QuickSort(ArrayIn,first,last){
    const x = ArrayIn[last-1];
    let i = first - 1;
    for(let j=first;j<last-1;j++){
        if(ArrayIn[j]<=x){
            i++;swap(ArrayIn,i,j);
        }
    }
    swap(ArrayIn,i+1,last-1);
    return i+1;
}

function QuickSort(ArrayIn,first=0,last){
    last = last||ArrayIn.length;
    if(first <last -1){
        const q=Part_QuickSort(ArrayIn,first,last);
        QuickSort(ArrayIn,first,q);
        QuickSort(ArrayIn,q+1,last);
    }
    return ArrayIn;
}

var array_test=new Array()
for(var index = 0;index< 64;index++){
    array_test[index]= parseInt(Math.random() * 100);
}
console.log("The orignal array: ");
console.log(array_test);
QuickSort(array_test,0,array_test.length);
console.log("After sort: ");
console.log(array_test);